/**
 * Created by Administrator on 2015/12/18.
 */
String.prototype.startWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
};
String.prototype.contains = function (item) {
    return RegExp("\\b" + item + "\\b").test(this);
};
Date.prototype.formatDateDef = function (format) {
    var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}
function getId(gridId) {
    var rowKey = $("#" + gridId + "").getGridParam("selrow");
    if (!rowKey) {
        ShowMessages("对不起,您没有选中任何记录", "系统提示", "msgwaring", null, 0);
        return [];
    } else {
        var selectedIDs = $("#" + gridId + "").getGridParam("selarrrow");
        var strJson = "";
        var jsonArr = new Array();
        for (var i = 0; i < selectedIDs.length; i++) {
            var rowData = $("#" + gridId + "").jqGrid("getRowData", selectedIDs[i]); //根据上面的id获得本行的所有数据
            jsonArr[i] = rowData;
        }
        return jsonArr;
    }
}

$(function () {
    document.onkeydown = function (e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
            $("li[defaultkey='13']").click();
            return false;
        }
    }
    $("a[name^='annexType']").next("a").click(function () {

        showAttachment($(this))
    });
});

function delateAttachment(fileIndx) {
    layer.confirm("确定删除附件吗?", function () {
        $.ajax({
            type: "post",
            async: false,
            dataType: "json",
            url: $basePath + "/uploadfile/delFile",
            data: {indx: fileIndx},
            success: function (data) {
                if (data) {
                    $("#fileOther" + fileIndx).parent().remove();
                    showOKMessage("附件删除成功");
                } else {
                    showWarningMsg("附件删除失败")
                }
            }, error: function () {
                showWarningMsg("附件删除失败");
            }
        });
    });
}
function showAttachment($this) {
    if ($this.attr("url") == "" || $this.attr("url") == undefined) {
        showWarningMsg("附件暂未上传！");
    } else {
        var url = $this.attr("url");
        if (url.indexOf('.jpeg') > 0 || url.indexOf('.jpg') > 0 || url.indexOf('.gif') > 0 || url.indexOf('.png') > 0) {
            layer.open({
                type: 2, area: ['700px', '530px'], fix: false, title: "附件查看", //不固定
                maxmin: true, content: $this.attr("url")
            });
        } else {
            showWarningMsg("无法预览，请下载查看！");
        }

    }
}

window.console = window.console || (function () {
        var c = {};
        c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function () {
        };
        return c;
    })();


function inhibitInput() {
    $("input[type=text]").attr("disabled", "disabled");
    $("input[type=checkbox]").attr("disabled", "disabled");
    $(".input2").attr("readonly", "readonly");
    $("textarea").attr("disabled", "disabled");
    $("select").attr("disabled", "disabled");
    $(".uploadCustom").hide();
}

function hasAuth(name) {
    //if ('000000' != $orgCode) {
    //    $("span[name='" + name + "']").html("");
    //}
}
function collStatus(cellvalue, options, rowObject) {
    if ('1' == cellvalue) {
        return "上报";
    } else if ('2' == cellvalue) {
        return "下发";
    } else {
        return "";
    }
}